﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using EntityModel;
using BusinessLayer;
using System.Drawing;

namespace PL___Web_Application
{
    public partial class PrivateAccount : PagesMethods
    {
        Private loggedprivate;
        protected void Page_Load(object sender, EventArgs e)
        {
            CheckCookie();
            loggedprivate = GetPrivateFromCookie();
             BL controller = new BL();
            Session["PurchasedCars"] = controller.purchasedCarsList(GetPrivateFromCookie());
            

            if (!Page.IsPostBack)
            {
                username_tb.Text = loggedprivate.Customer.username;
                password_tb.Text = loggedprivate.Customer.password;
                name_tb.Text = loggedprivate.name;
                cpr_tb.Text = loggedprivate.cpr.ToString();
                address_tb.Text = loggedprivate.Customer.address_c;
                phone_tb.Text = loggedprivate.Customer.phone.ToString();
                age_tb.Text = loggedprivate.age.ToString();
                sex_cb.SelectedValue = loggedprivate.sex;
            }

        }

        protected void Save_Changes(object sender, EventArgs e)
        {
            loggedprivate.Customer.username = username_tb.Text;
            loggedprivate.Customer.password = password_tb.Text;
            loggedprivate.name = name_tb.Text;
            loggedprivate.cpr = Convert.ToInt32(cpr_tb.Text);
            loggedprivate.Customer.address_c = address_tb.Text;
            loggedprivate.Customer.phone = Convert.ToInt32(phone_tb.Text);
            loggedprivate.age = Convert.ToInt32(age_tb.Text);
            loggedprivate.sex = sex_cb.SelectedValue;

            try {
                BL controller = new BL();
                controller.updatePrivateCustomer(loggedprivate);
                error_lb.ForeColor = Color.Blue;
                error_lb.Text = "Your data was correctly updated";
            }
            catch (Exception ex) { error_lb.Text = ex.Message; }

        }

        public List<Car> purchasedCarsList() {
            return (List<Car>)Session["PurchasedCars"];
           
        }
    }


}